package com.arvato.minipro.service.mall;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.arvato.minipro.bean.bean_do.mall.EcCategoryDo;
import com.arvato.minipro.bean.bean_dto.common.PageData;
import com.arvato.minipro.bean.bean_dto.common.Query;
import com.arvato.minipro.bean.bean_vo.mall.EcCategoryVo;
import com.arvato.minipro.mapper.mall.EcCategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * Describe：商品分类service
 * 
 * @author smallking
 *
 *  2018年2月8日
 */
@Service
@Transactional
public class CategoryService {
	@Autowired
	private EcCategoryMapper categoryMapper;
	
	/**
	 * 根据ID查询商品分类
	 * @param categoryId
	 * @return
	 */
	public EcCategoryVo getCategoryById(String categoryId) {
		return categoryMapper.getCategoryById(categoryId);
	}
	/**
	 * 根据条件查询(含分页)
	 * @param query
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	public PageData listCategoryByQuery(Query query, Integer pageNum, Integer pageSize) {
		// 设置分页参数
		PageHelper.startPage(pageNum, pageSize);
		// 开启查询
		List<EcCategoryVo> categoryList = categoryMapper.listCategoryByQuery(query);
		// 得到分页结果
		PageInfo<EcCategoryVo> pageInfo = new PageInfo<EcCategoryVo>(categoryList);
		return new PageData(pageInfo.getTotal(), pageInfo.getList());
	}
	/**
	 * 按照条件查询分类(不分页)
	 * @param query
	 * @return
	 */
	public List<EcCategoryVo> listCategoryByQuery(Query query) {
		return categoryMapper.listCategoryByQuery(query);
	}
	/**
	 * 新增一个商品分类
	 * @param categoryDo
	 * @return
	 */
	public int insert(EcCategoryDo categoryDo) {
		return categoryMapper.insert(categoryDo);
	}

	/**
	 * 修改一个商品分类
	 * @param categoryDo
	 * @return
	 */
	public int update(EcCategoryDo categoryDo) {
		return categoryMapper.update(categoryDo);
	}

	/**
	 * 删除一个商品分类
	 * @param categoryId
	 * @return
	 */
	public int delete(String categoryId) {
		return categoryMapper.delete(categoryId);
	}

	
}
